<template>
  <div>
    <el-dialog title="图纸选择"
               v-if="showFlag"
               :visible.sync="showFlag"
               :modal=false
               width="80%"
               center
    >
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="图纸名称" prop="lineName">
          <el-input
            v-model="queryParams.lineName"
            placeholder="请输入图纸名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="图号" prop="lineNumber">
          <el-input
            v-model="queryParams.lineNumber"
            placeholder="请输入图号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="drawingList" @selection-change="handleSelectionChange" border>
        <el-table-column type="selection" width="50" align="center"/>
        <el-table-column label="图纸名称" align="center" prop="lineName"/>
        <el-table-column label="图号" align="center" prop="lineNumber"/>
        <el-table-column label="图纸描述" align="center" prop="remark"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleView(scope.row)"
            >查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改图纸集Line对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <iframe
        :src="form.lineUrl"
        frameborder="0"
        scrolling="auto"
        style="width: 100%; height: 600px;"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getDrawingline, getByDrawCode } from "@/api/mes/md/drawingline";

export default {
  name: "DrawingMultiSelect",
  props: {
    drawCode: null,
  },
  data() {
    return {
      showFlag: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 用户表格数据
      drawingList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},

      // 查询参数
      queryParams: {
        drawCode: this.drawCode,
        lineName: null,
        lineNumber: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      if (this.queryParams.drawCode !== null && this.queryParams.drawCode !== '') {
        getByDrawCode(this.queryParams).then(response => {
          this.drawingList = response.data;
          this.loading = false;
        });
      }else {
        this.drawingList = [];
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.selectedRows = selection;
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    //确定选中
    confirmSelect() {
      if (this.selectedRows == null || this.selectedRows.length == 0) {
        this.$notify({
          title: '提示',
          type: 'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected', this.selectedRows);
      this.showFlag = false;
    },
    // 查看图纸
    handleView(row) {
      this.open = true;
      getDrawingline(row.id).then(response => {
        this.form = response.data;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
  }
};
</script>
